package com.example.dell.startproject212lh;



        import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
        import android.view.View;
        import android.widget.Button;
        import android.widget.EditText;
        import android.widget.TextView;

        import com.example.dell.startproject212lh.Ibace.WeatherListener;
        import com.example.dell.startproject212lh.bean.Weatherinfo;
        import com.example.dell.startproject212lh.modl.WeatherModel;

public class MainActivity extends AppCompatActivity  implements WeatherListener, View.OnClickListener {
    private EditText etcity;
    private Button btnfind1, btnfind2;
    private TextView tvcityname;
    private int btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();//调用初始化方法
    }

    private void init() {
        etcity = (EditText) findViewById(R.id.editText2);
        btnfind1 = (Button) findViewById(R.id.button);
        btnfind2 = (Button) findViewById(R.id.button2);
        tvcityname = (TextView) findViewById(R.id.textView);

        btnfind1.setOnClickListener(this);
        btnfind2.setOnClickListener(this);
    }

    @Override
    public void onResponse(Weatherinfo weatherinfo) {
        if(weatherinfo!=null){
            if(btn==1){
                tvcityname.setText(weatherinfo.getCity());
            }else {
                tvcityname.setText(weatherinfo.getCity() + weatherinfo.getSD() + weatherinfo.getTemp() + weatherinfo.getWD() + weatherinfo.getWS());
            }
        }else {
            tvcityname.setText("未知");
        }

    }

    @Override
    public void onFall(String msg) {
        tvcityname.setText(msg);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                WeatherModel weatherModl = new WeatherModel();
                weatherModl.getWeather(etcity.getText().toString(), this);
                btn=1;
                break;
            case R.id.button2:
                WeatherModel weatherModel1=new WeatherModel();
                weatherModel1.getWeather(etcity.getText().toString(),this);
                btn=2;
                break;

        }
    }
}

